//
//  JJWelcomeViewController.swift
//  JJSina
//
//  Created by mac on 2017/12/6.
//  Copyright © 2017年 xinyuan. All rights reserved.
//

import UIKit
/*
 1. 背景图片
 2.用户头像
 3.文字
 */
class JJWelcomeViewController: UIViewController {

    override func loadView() {
        super.loadView()
        view = bgImageView
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(userIcon)
        view.addSubview(messageLabel)
        userIcon.snp.makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalTo(view).offset(400)
        }
        messageLabel.snp.makeConstraints { (make) in
            make.top.equalTo(userIcon.snp.bottom).offset(16)
            make.centerX.equalToSuperview()
        }
    }
    
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        userIcon.snp.updateConstraints({ (make) in
            make.top.equalTo(self.view).offset(100)
        })
        UIView.animate(withDuration: 2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {()->() in
            self.view.layoutIfNeeded()
            
        }, completion: {(_)->() in
            UIView.animate(withDuration: 0.25, animations: {
                self.messageLabel.alpha = 1
            }, completion: { (_) in
                NotificationCenter.default.post(name: NSNotification.Name(rawValue: JJ_CHANGE_ROOTCONTROLLER_NOTIFICATION), object: "welcomeVC")
            })
        })
    }
    
    
    private lazy var bgImageView: UIImageView = UIImageView(imageName: "ad_background")
    private lazy var userIcon: UIImageView = {
        let img = UIImageView(imageName: "avatar_default")
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        img.layer.borderColor = JJ_THEMECOLOR.cgColor
        img.layer.borderWidth = 1
        img.jj_setImage(urlString: JJOAuthViewModel.shared.userAccountModel?.avatar_large)
        return img
    }()
    private lazy var messageLabel: UILabel = {
        let lab = UILabel()
        lab.text = "北京,你好!"
        lab.textAlignment = .center
        lab.alpha = 0
        return lab
    }()
}
